package springinpractice.ch8.news.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import springinpractice.ch8.news.dao.NewsItemDao;
import springinpractice.ch8.news.model.NewsItem;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

@Service("newsService")
@Transactional(
	propagation = Propagation.REQUIRED,
	isolation = Isolation.DEFAULT,
	readOnly = true)
public class NewsServiceImpl implements NewsService {
	private NewsItemDao newsItemDao;
	private int maxResults = 10;
	
	
	// ========================================================================
	// Dependency injection methods
	// ========================================================================
	
	public void setNewsItemDao(NewsItemDao newsItemDao) {
		this.newsItemDao = newsItemDao;
	}
	
	public void setRecentNewsMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}
	
	
	// ========================================================================
	// Service methods
	// ========================================================================
	
	public List<NewsItem> getRecentNews() {
		return newsItemDao.getListByDateDesc(maxResults);
	}
}
